﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;

namespace Model.WaiGaoQiao
{
   public class Work_ArticleUnit
    {
         private DataAccessWork_ArticleUnit workArticleUnitAccess;

        public Work_ArticleUnit()
        {
            workArticleUnitAccess = new DataAccessWork_ArticleUnit();
        }
        /// <summary>
        /// 规格数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_ArticleUnitCount(string Condition)
        {
            return workArticleUnitAccess.GetWork_ArticleUnitCount(Condition);
        }

        #region  ---------字段------------
        /// <summary>
        /// Id
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 物资ID
        /// </summary>
        public int AID { get; set; }
        /// <summary>
        /// 规格
        /// </summary>
        public string Unit { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        

        #endregion
       
        /// <summary>
        ///根据id获取劳资规格对象
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public Work_ArticleUnit GetCon_ArticleUnitById(int Id)
        {
            Work_ArticleUnit comInfo = new Work_ArticleUnit();
            DataSet ds = workArticleUnitAccess.GetWork_ArticleUnitById(Id);

            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                DataRow item = ds.Tables[0].Rows[0];

                comInfo = new Work_ArticleUnit()
                {
                    ID = Convert.ToInt32(item[0]),
                    AID =Convert.ToInt32(item[1]),
                    Unit = item[2].ToString(),
                    Remark = item[3].ToString(),
                 };
            }
            return comInfo;
        }
        /// <summary>
        /// 保存或修改劳保物资规格
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveWork_ArticleUnit(Work_ArticleUnit dminfo)
        {
            object[] dpmpara = new object[] {dminfo.ID, dminfo.AID,dminfo.Unit,dminfo.Remark };
            return workArticleUnitAccess.SaveWork_ArticleUnit(dpmpara);
        }
        /// <summary>
        /// 根据条件获取所有劳资规格。
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Work_ArticleUnit> GetAllCon_ArticleUnit(string condition)
        {
            IList<Work_ArticleUnit> dmlist = new List<Work_ArticleUnit>();
            Work_ArticleUnit dminfo;
            DataSet ds = workArticleUnitAccess.GetAllWork_ArticleUnit(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Work_ArticleUnit();
                {
                    dminfo.ID = Convert.ToInt32(item[0]);
                    dminfo.AID =Convert.ToInt32(item[1]);
                    dminfo.Unit = item[2].ToString();
                    dminfo.Remark = item[3].ToString();
               
                }
                dmlist.Add(dminfo);

            }
            return dmlist;
        }
        /// <summary>
        /// 获取所有劳资规格(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Work_ArticleUnit> GetAllCon_ArticleUnit(string Condition, int pagesize, int startindex)
        {
            IList<Work_ArticleUnit> dmlist = new List<Work_ArticleUnit>();
            Work_ArticleUnit dminfo;
            DataSet ds = workArticleUnitAccess.GetAllWork_ArticleUnit(Condition, pagesize, startindex);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Work_ArticleUnit();
                {
                    dminfo.ID = Convert.ToInt32(item[0]);
                    dminfo.AID = Convert.ToInt32(item[1]);
                    dminfo.Unit = item[2].ToString();
                    dminfo.Remark = item[3].ToString();
                }
                dmlist.Add(dminfo);

            }
            return dmlist;
        }

        
        /// <summary>
        /// 删除劳保物资规格
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteWork_ArticleUnit(string id)
        {
            return workArticleUnitAccess.DeleteWork_ArticleUnit(id);
        }
    }
}
